<template>
	<view class="">
		<u-navbar :is-back="true" back-icon-color="#333" :background="background" back-text="客户信息" title-color="#333"
			:back-text-style="{ color: '#333' }">
			<view class="navbar-right" slot="right">
				<view class="dot-box right-item">
					<text @tap="onNavigationBar" v-show="$rule('wodekehu/tianjia')">添加</text>
				</view>
			</view>
		</u-navbar>
		<u-swipe-action :show="item.show" :index="index" v-for="(item, index) in list" :key="item.id" @click="click"
			@open="open" :options="options">
			<view class="item u-border-bottom" @tap="contentclick(item.id)">
				<view class="title-wrap">
					<text class="title u-line-2">客户名称：{{ item.name }}</text>
					<text class="title u-line-2">客户等级：{{ item.level }}</text>
					<text class="title u-line-2">联系人：{{ item.contact }}</text>
					<text class="title u-line-2">联系方式：{{ item.phone }}</text>
					<text class="title u-line-2">公司电话：{{ item.telephone }}</text>
					<text class="title u-line-2">账期(天)：{{ item.period }}</text>
					<text class="title u-line-2">状态：{{ item.status }}</text>
				</view>
			</view>
		</u-swipe-action>
		<u-modal v-model="show" v-show="$rule('wodekehu/shanchu')" content="是否删除该信息？" :show-cancel-button="true" @confirm="confirm"></u-modal>
		<u-toast ref="uToast" />
	</view>
</template>
<script>
var _this;
export default {
	data() {
		return {
			background: {
				// 渐变色
				backgroundImage: 'linear-gradient(45deg, rgb(255, 255, 255), rgb(255, 255, 255))'
			},
			list: [],
			show: false,
			options: [
				{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}
			],
			id: null,
			value: '',
			type: 'text',
			border: true
		}
	},
	onLoad() {
		_this = this;
		_this.getlist();
	},
	onShow() {
		_this.getlist();
	},
	onNavigationBarButtonTap(e) {
		uni.navigateTo({
			url: 'add'
		})
	},
	methods: {
		onNavigationBar() {
			uni.navigateTo({
				url: 'add'
			})
		},
		getlist() {
			_this._post_form('/api/ykjp/information/basisinfo/customerinfo/index', {}, (result) => {
				// 数组反转
				result.data.data.reverse();
				_this.setData({ 'list': result.data.data })
			});
		},
		click(index, index1) {
			_this.show = true;
			_this.id = this.list[index].id;
		},
		open(index) {
			this.list[index].show = true;
		},
		confirm() {
			_this._post_form('/api/ykjp/information/basisinfo/customerinfo/del', {
				id: _this.id
			}, (result) => {
				_this.getlist()
			});
		},
		contentclick(e) {
			uni.navigateTo({
				url: 'details?id=' + e
			})
		}
	}
}
</script>
<style lang="scss" scoped>
.item {
	display: inherit;
	padding: 20rpx;
}

.title {
	text-align: left;
	font-size: 28rpx;
	color: $u-content-color;
	margin-top: 20rpx;
}

.title-wrap {
	display: inline-block;
}

.navbar-right {
	margin-right: 24rpx;
	display: flex;
}

.right-item {
	margin: 0 12rpx;
	position: relative;
	color: #333333;
	display: flex;
}
</style>
